

#ifndef _ULTRA_KS104_H_
#define _ULTRA_KS104_H_

#include "ringbuff.h"

#define KS104_ALL_NUM        10
#define KS104_USE_NUM        8
#define KS104_COMM_OVERTIME  10

#define KS104_START_DELAY    5000

typedef enum
{
	ID_KS104_X0 = 0xE0,	
	ID_KS104_X1 = 0xE2,
	ID_KS104_X2 = 0xE8,
	ID_KS104_X3 = 0xD0,
	ID_KS104_X4 = 0xD2,
	ID_KS104_X5 = 0xD4,
	ID_KS104_X6 = 0xD6,
	ID_KS104_X7 = 0xD8,
	ID_KS104_X8 = 0xDA,
	ID_KS104_X9 = 0xDC,

}ENUM_KS104_ID;


typedef enum
{
	FSM_KS104_NORMAL = 0,
	FSM_KS104_FAULT = 1

}ENUM_KS104_FSM;


typedef struct
{
	uint8_t ID;
	uint8_t dataH;
	uint8_t dataL;
	uint8_t checksum;

}STR_KS104_RAW;


typedef struct
{
	ENUM_KS104_FSM  status;
	uint8_t  ID;
	uint16_t NUM;
	uint16_t comm_cnt;
	uint16_t distance_mm;
	
}STR_KS104_HDL;



extern void KS104_measure_rece(STR_RINGBUF *bufhdl);
extern void KS104_measure_send(STR_RINGBUF *bufhdl);
extern void KS104_start_ctrl(uint8_t power_status, uint16_t run_time);

extern STR_KS104_HDL KS104Hdl[KS104_ALL_NUM];


static inline uint16_t get_KS104_distance(uint8_t num)
{
	if(num < KS104_ALL_NUM)
	{
		return KS104Hdl[num].distance_mm;
	}		
	else
	{
		return 0;
	}
}




#endif

